///////////////////////////////////////////////////////////////////////////////
//
//  Copyright (C) 2009. Dimarik
//
///////////////////////////////////////////////////////////////////////////////

package
{

import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.IEventDispatcher;
import flash.media.Sound;
import flash.utils.getClassName;

import ru.goodcore.utils.ActivityListener;

/**
 *  @author				Dimarik
 *  @version			1.0
 *  @langversion		3.0
 *  @playerversion		9.0
 * 
 */
[SWF(width="800", height="600", frameRate="21", backgroundColor="#E0EEEE")]
[Frame(factoryClass="ApplicationFactory")]

public class FramedApplicationTest extends Sprite {

	//-------------------------------------------------------------------------
	//
	//   Private
	//
	//-------------------------------------------------------------------------
	[Embed (source="../src_assets/sound/Aliens_Lair_Theme.mp3")]
	private var _soundtrack:Class;

	[Embed (source="../src_assets/gfx/character/contra_run.swf", symbol="Run")]
	private var _preloader:	Class;

	//-------------------------------------------------------------------------
	//
	//   Constructor
	//
	//-------------------------------------------------------------------------

	public function FramedApplicationTest() {
		super();
		super.addEventListener(Event.ADDED_TO_STAGE, this.initialize);
	}

	//-------------------------------------------------------------------------
	//
	//   Private variables
	//
	//-------------------------------------------------------------------------
	
	/**
	 * @private 
	 */
	private var _activity:		ActivityListener;

	//-------------------------------------------------------------------------
	//
	//   Private methods
	//
	//-------------------------------------------------------------------------

	public function initialize(event:Event):void {
		(event.target as IEventDispatcher).removeEventListener(event.type, arguments.callee);

		super.stage.scaleMode = StageScaleMode.NO_SCALE;
		super.stage.align = StageAlign.TOP_LEFT;

		trace(getClassName(this), 'initialize');

		this._activity = new ActivityListener();
		super.stage.addChild(this._activity);

		var sound:Sound = new this._soundtrack() as Sound;
		if (sound)
			sound.play();

		var preloader:DisplayObject = new this._preloader() as DisplayObject;

		super.addChild(preloader);
		preloader.x = super.stage.stageWidth >> 1;
		preloader.y = super.stage.stageHeight >> 1;
	}

	//-------------------------------------------------------------------------
	//
	//   Events handlers
	//
	//-------------------------------------------------------------------------

}
}